package org.zoomdev.zoom.aop.test.shop.interceptor;

import org.zoomdev.zoom.aop.Interceptor;
import org.zoomdev.zoom.aop.Invoker;
import org.zoomdev.zoom.aop.test.shop.services.CallRecord;

import java.lang.reflect.Method;

public class LogInterceptor implements Interceptor {

    private final CallRecord record;

    public LogInterceptor(CallRecord record) {
        this.record = record;
    }


    @Override
    public Object intercept(Invoker invoker, Method method, Object target, Object[] args) throws Throwable {
        record.add(method);
        System.out.println("Method invoke :" + method);
        return invoker.invoke(target, args);
    }
}
